home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / uucp / permissions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-26  |  4.3 KB  |  184 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "../misc/misc.h"
  4. #include "internal.h"
  5. #include "uucp.h"
  6. #include "uucp.m"
  7. #include "../paths.h"
  8.  
  9. extern UUCP_HELP_FILE help_uucp;
  10. static CONFIG_FILE f_perms (VAR_LIB_UUCP_PERMS
  11.     ,help_uucp
  12.     ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED
  13.     ,"uucp","uucp",0660);
  14.  
  15. static const char MACHINE[] = "MACHINE";
  16. static const char COMMANDS[] = "COMMANDS";
  17. static const char LOGNAME[] = "LOGNAME";
  18. static const char MYNAME[] = "MYNAME";
  19. static const char READ[] = "READ";
  20. static const char WRITE[] = "WRITE";
  21. static const char SENDFILES[] = "SENDFILES";
  22. static const char REQUEST[] = "REQUEST";
  23.  
  24.  
  25.  
  26. PUBLIC PERMISSION::PERMISSION ()
  27. {
  28.     commands.setfrom ("rmail:rnews");
  29.     dirread.setfrom ("/var/spool/uucppublic");
  30.     dirwrite.setfrom ("/var/spool/uucppublic");
  31.     maysend = mayrequest = 1;
  32. }
  33.  
  34. PUBLIC PERMISSION::PERMISSION (const PERMISSION *p)
  35. {
  36.     commands.setfrom (p->commands);
  37.     dirread.setfrom (p->dirread);
  38.     dirwrite.setfrom (p->dirwrite);
  39.     maysend = p->maysend;
  40.     mayrequest = p->mayrequest;
  41.     logname.setfrom(p->logname);
  42.     myname.setfrom (p->myname);
  43.     comments.setfrom (p->comments);
  44.     machine.setfrom (p->machine);
  45. }
  46.  
  47. PUBLIC PERMISSION::PERMISSION (
  48.     const char *buf,    // Buffer to parse from the Permissions file
  49.     const SSTRING &_comments,    // Comments preceding the definition
  50.     char *err)            // Will contain error message or '\0'
  51. {
  52.     comments.setfrom (_comments);
  53.     comments.strip_end();
  54.     err[0] = '\0';
  55.     while (1){
  56.         char word[1000];
  57.         buf = str_copyword(word,buf);
  58.         if (word[0] == '\0'){
  59.             break;
  60.         }else{
  61.             char *equal = strchr(word,'=');
  62.             if (equal != NULL){
  63.                 *equal++ = '\0';
  64.                 if (strcmp(word,MACHINE)==0){
  65.                     machine.setfrom (equal);
  66.                 }else if (strcmp(word,COMMANDS)==0){
  67.                     commands.setfrom (equal);
  68.                 }else if (strcmp(word,LOGNAME)==0){
  69.                     logname.setfrom (equal);
  70.                 }else if (strcmp(word,MYNAME)==0){
  71.                     myname.setfrom (equal);
  72.                 }else if (strcmp(word,READ)==0){
  73.                     dirread.setfrom (equal);
  74.                 }else if (strcmp(word,WRITE)==0){
  75.                     dirwrite.setfrom (equal);
  76.                 }else if (strcmp(word,SENDFILES)==0){
  77.                     maysend = stricmp(equal,"yes")==0;
  78.                 }else if (strcmp(word,REQUEST)==0){
  79.                     mayrequest = stricmp(equal,"yes")==0;
  80.                 }else{
  81.                     err += sprintf (err,MSG_U(E_IVLKEYW
  82.                         ,"Invalid keyword \"%s\"\n")
  83.                         ,word);
  84.                 }
  85.             }else{
  86.                 err += sprintf (err,MSG_U(E_IVLKEYPAIR
  87.                     ,"Invalid keyword value pair\n"
  88.                      "expected an equal sign\n"
  89.                      "\t%s\n")
  90.                     ,word);
  91.             }
  92.         }
  93.     }
  94. }
  95.  
  96. static void fputs_cond (
  97.     const char *key,
  98.     const char *val,
  99.     int &first_line,        // Is it the first line we print
  100.     FILE *fout)
  101. {
  102.     if (val[0] != '\0'){
  103.         if (first_line){
  104.             first_line = 0;
  105.         }else{
  106.             fputs (" \\\n\t",fout);
  107.         }
  108.         fprintf (fout,"%s=%s",key,val);
  109.     }
  110. }
  111.  
  112. static void fputs_cond (
  113.     const char *key,
  114.     const SSTRING &val,
  115.     int &first_line,        // Is it the first line we print
  116.     FILE *fout)
  117. {
  118.     fputs_cond (key,val.get(),first_line,fout);
  119. }
  120.  
  121. /*
  122.     Write one record in the Permissions file
  123. */
  124. PUBLIC void PERMISSION::write (FILE *fout)
  125. {
  126.     comment_write (comments,fout);
  127.     int first_line = 1;
  128.     fputs_cond (MACHINE,machine,first_line,fout);
  129.     fputs_cond (LOGNAME,logname,first_line,fout);
  130.     fputs_cond (MYNAME,myname,first_line,fout);
  131.     fputs_cond (COMMANDS,commands,first_line,fout);
  132.     fputs_cond (READ,dirread,first_line,fout);
  133.     fputs_cond (WRITE,dirwrite,first_line,fout);
  134.     fputs_cond (REQUEST,mayrequest ? "yes" : "no",first_line,fout);
  135.     fputs_cond (SENDFILES,maysend ? "yes" : "no",first_line,fout);
  136.     fputc ('\n',fout);
  137. }
  138.  
  139. PUBLIC PERMISSION *PERMISSIONS::getitem(int no)
  140. {
  141.     return (PERMISSION*)ARRAY::getitem(no);
  142. }
  143.  
  144. /*
  145.     Locate one machine Permission spec
  146. */
  147. PUBLIC PERMISSION *PERMISSIONS::getitem(const char *machine, int &no)
  148. {
  149.     int n = getnb();
  150.     PERMISSION *ret = NULL;
  151.     for (int i=no; i<n; i++){
  152.         PERMISSION* p = getitem(i);
  153.         if (p->machine.cmp(machine)==0){
  154.             ret = p;
  155.             no = i+1;
  156.             break;
  157.         }
  158.     }
  159.     return ret;
  160. }
  161.  
  162. /*
  163.     Locate one machine Permission spec
  164. */
  165. PUBLIC PERMISSION *PERMISSIONS::getitem(const char *machine)
  166. {
  167.     int no=0;
  168.     return getitem (machine,no);
  169. }
  170.  
  171. PUBLIC PERMISSIONS::PERMISSIONS()
  172.     : CONFIG_OBJS (f_perms)
  173. {
  174. }
  175.  
  176. PROTECTED CONFIG_OBJ *PERMISSIONS::newobj (
  177.     const char *buf,    // Buffer to parse from the Permissions file
  178.     const SSTRING &_comments,    // Comments preceding the definition
  179.     char *err)            // Will contain error message or '\0'
  180. {
  181.     return new PERMISSION (buf,_comments,err);
  182. }
  183.  
  184.